<?php

class Welcome extends Controller {

	function Welcome()
	{
		
		parent::Controller();
	}
	
	function index()
	{
		
		global $debug;
		$this->load->helper('url');
		$url =  base_url()."wp";
		$this->load->library("cache");
		$html = $this->cache->get("home");
		if(empty($html))
		{
			$html =  file_get_contents($url);
			$this->cache->set("home",$html);	
		}else{
			if($debug) 
				echo "is cached!";
		}
		echo $html;
	}
	
	function xmlrpc()
	{
	   $this->load->library('xmlrpc');
	   $this->load->helper('date');
	   $blogid = 1;
	   $bloguser = "ttsgs";
	   $blogpass = "ttsgs007";
	   $publishImmediately = "true";
	   $thePost = array(array('title'  => array('this is the title','string'),
	                           'description'    => array('this is the description','string'),
	                           'dateCreated' => array('2009-12-10T16:57:53Q','datetime.iso8601'),
	                           ),
	                    'struct');
		$myPost = "my post";
	   $this->xmlrpc->set_debug(TRUE);
	   $this->xmlrpc->server("http://wp.ttsgs.com/xmlrpc.php", 80);
	   $this->xmlrpc->method('metaWeblog.newPost');
	  	$time = time();
      	$mydate=standard_date('DATE_W3C', $time);
      	$content = 'this is the description';	   
      	$title = 'this is the title';
      	$mydate= '2005-12-13T01:35:00Z';
      	//$mydate= '2005-12-13';
		$post=array(array(
		'dateCreated' =>array($mydate,'datetime.iso8601'),
		'description' =>array( $content,'string'),
		'title'  =>array( $title,'string')),'struct'
		
		);	
	   $request = array($blogid, $bloguser, $blogpass, $post, array($publishImmediately,'boolean'));
	
	   $this->xmlrpc->request($request);
	   $result = $this->xmlrpc->send_request();
	
	   if ( !$result )
	   {
	       echo $this->xmlrpc->display_error();
	   }
	   else
	   {
	       echo '<pre>';
	       print_r($this->xmlrpc->display_response());
	       echo '</pre>';
	   }
	}
	
	
	function xmlrpc_1()
	{
	   $this->load->library('xmlrpc');
	   $this->load->helper('date');
	   $blogid = 1;
	   $bloguser = "ttsgs";
	   $blogpass = "ttsgs007";
	   //$this->xmlrpc->set_debug(TRUE);
	   $this->xmlrpc->server("http://wp.ttsgs.com/xmlrpc.php", 80);
	   $this->xmlrpc->method('blogger.getUsersBlogs');
	   $request = array($blogid, $bloguser, $blogpass);
	   $this->xmlrpc->request($request);
	   $result = $this->xmlrpc->send_request();
	   if ( !$result )
	   {
	       echo $this->xmlrpc->display_error();
	   }
	   else
	   {
	       echo '<pre>';
	       print_r($this->xmlrpc->display_response());
	       echo '</pre>';
	   }
	}	
	
	function getRecentPosts($bloguser,$blogpass)
	{
	   $bloguser = "ttsgs";
	   $blogpass = "ttsgs007";
	   		
	   $this->load->library('xmlrpc');
	   $this->load->helper('date');
	   $blogid = 1;
	   $this->xmlrpc->server("http://wp.hjue.net/xmlrpc.php", 80);
	   //$this->xmlrpc->server("http://wp.ttsgs.com/xmlrpc.php", 80);
	   $this->xmlrpc->method('metaWeblog.getRecentPosts');
	   $request = array($blogid, $bloguser, $blogpass);
	   $this->xmlrpc->request($request);
	   $result = $this->xmlrpc->send_request();
	   if ( !$result )
	   {
	       echo $this->xmlrpc->display_error();
	       return array();
	   }
	   else
	   {
	       $ret = $this->xmlrpc->display_response();
	       return $ret;
	   }
	}
		
	public function newPost($bloguser,$blogpass,$title,$body,$date){

	   $bloguser = "ttsgs";
	   $blogpass = "ttsgs007";
	   	
	   	$title="AAAAAAAAAAAAAAAa";
	   	$body ="asdfasfasdfasf";
	   	$date = "2011-1-15";
	   	
	   $this->load->library('xmlrpc');
	   $this->load->helper('date');
	   $blogid = 1;

	   $publishImmediately = "true";

	   //$this->xmlrpc->set_debug(TRUE);
	   $this->xmlrpc->server("http://wp.hjue.net/xmlrpc.php", 80);
	   //$this->xmlrpc->server("http://wp.ttsgs.com/xmlrpc.php", 80);
	   $this->xmlrpc->method('metaWeblog.newPost');
  	
		$fdate = date("Ymd\TH:i:s\Z",strtotime($date));
		
		      	
      	$categories = array("Uncategorized", "Blogroll", "Reviews");
      	//'categories' => array($categories,'struct'),
      	
		$post=array(array(
		'dateCreated' =>array($fdate,'dateTime.iso8601'),
		'description' =>array( $body,'string'),
		'title'  =>array( $title,'string')),'struct'
		
		);	
	   $request = array($blogid, $bloguser, $blogpass, $post, array($publishImmediately,'boolean'));
	
	   $this->xmlrpc->request($request);
	   $result = $this->xmlrpc->send_request();
	
	   if ( !$result )
	   {
	       echo $this->xmlrpc->display_error();
	   }
	   else
	   {
	       return $this->xmlrpc->display_response();
	   }
	} 	
	
	
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */